<?php $total_check_advances = 0;?>
<table class="datagrid" style="width:300px;">
  <thead class="datagrid">
    <tr>
      <th>
        Payment Date
      </th>
      <th>
        Payment#
      </th>
      <th>
        Check#
      </th>
      <th>
        Check Date
      </th>
      <th>
        Balance Remaning
      </th>
    </tr>
  </thead>
  <tbody class="datagrid" style="height:auto;">
    <?php foreach($check_advances as $check_advance):?><tr>
      <td>
        <?php echo $check_advance['document_date'] ?>
      </td>
      <td>
        <?php echo $check_advance['payment_id'] ?>
      </td>
      <td>
        <?php echo $check_advance['check_id'] ?>
      </td>
      <td>
        <?php echo $check_advance['check_date'] ?>
      </td>
      <td style="text-align:right;">
        <?php echo number_format($check_advance['total'],2) ?>
      </td>
      </tr>
      <?php $total_check_advances += $check_advance['total'];?>
    <?php endforeach;?>
  </tbody>
  <tfoot class="datagrid">
    <tr>
      <td style="text-align:right;" colspan="4">Total</td>
      <td style="text-align:right;">
        <?php echo number_format($total_check_advances,2) ?>
      </td>
    </tr>
  </tfoot>
</table>